package com.zijie.hosptal.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zijie.hosptal.pojo.po.Log;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface LogMapper extends BaseMapper<Log> {
    @Insert("insert into log(user_name,all_name,name,operation_time,long_time) " +
            "values(#{userName},#{allName},#{name},#{operationTime},#{longTime})")
    public int insert(Log log);


    default Page<Log> list(Page<Log> page1, Log log){
        LambdaQueryWrapper<Log> wrapper = Wrappers.lambdaQuery();
        if (log.getLongTime() != null) {
            wrapper.gt(Log::getLongTime, log.getLongTime());
        }
        if (log.getName()!=null){
            wrapper.like(Log::getName,log.getName());
        }
        return selectPage(page1,wrapper);
    }

    @Delete("delete from log where id=#{id}")
    int removeById(Integer id);
}
